package com.ichir.projects.uiframework.xml;

import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlID;

import com.ichir.projects.uiflow.definition.IFlowPart;
import com.ichir.projects.uiflow.definition.ITransition;
import com.ichir.projects.uiflow.ui.api.IUiPart;

@XmlAccessorType(XmlAccessType.FIELD)
public abstract class XmlFlowPart implements IFlowPart {

	@XmlAttribute(required=true)
	@XmlID
	protected String id;
	
	@XmlAttribute(required=true, name="class")
	protected String clazz;

	@Override
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}

	@XmlElement(name="transition")
	protected List<XmlTransition> transitions;

	@Override
	public List<? extends ITransition> getTransitions() {
		return transitions;
	}

	/**
	 * @param transitions the transitions to set
	 */
	public void setTransitions(List<XmlTransition> transitions) {
		this.transitions = transitions;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Class<? extends IUiPart> getUiPartClassname() {
		try {
			return (Class<? extends IUiPart>) Class.forName(clazz);
		} catch (ClassNotFoundException e) {
			throw new RuntimeException(e);
		}
	}

	/**
	 * @param clazz the clazz to set
	 */
	public void setClazz(String clazz) {
		this.clazz = clazz;
	}
	
	/**
	 * @return the clazz
	 */
	public String getClazz() {
		return clazz;
	}
}
